data mydata.LCAaim2;
set mydata.LCAaim2;
ods rtf file= 'C:\Users\anakwea\Desktop\Men\RTF_results\2011_2019\descriptives_Aim1_10223';
 proc freq data=mydata.LCAaim2;
 tables insur reprohlth workcons pir educ hisprace2 immigrant pregint certain union 
		sexprt sexrisk condom hltstat drink drug sti bmi2 year;
run;
proc surveyfreq data=mydata.LCAaim2;
	tables (metro insur reprohlth workcons pir educ hisprace2 immigrant pregint certain union 
		sexprt sexrisk condom hltstat drink drug sti bmi2)* year/cl nowt row col chisq;
	weight WEIGHTVAR;
	cluster panelvar;
	strata stratvar;
run;
Proc surveymeans data=mydata.LCAaim2;
domain year/ diff;
var AGER VRY1STAG BIOKIDS;
     weight WEIGHTVAR;
	 cluster panelvar;
	 strata stratvar;
run;
Proc surveymeans data=mydata.LCAaim2;
class year;
var AGER VRY1STAG BIOKIDS;
     weight WEIGHTVAR;
	 cluster panelvar;
	 strata stratvar;
run;
ods rtf close; 
/************************DESCRIPTIVES BY YEAR**************************/
ods rtf file='C:\Users\anakwea\Desktop\Men\RTF_results\2011_2019\descriptives_preconp_10223';
proc surveyfreq data=mydata.LCAaim2;
	tables (sexprt2 sexrisk condom2 hltstat2 drink2 drug sti bmi3)*year/cl nowt row col chisq;
	weight WEIGHTVAR;
	cluster panelvar;
	strata stratvar;
run;
ods rtf close;
/*************************THE LCA MODELS (N= 10,223)************************************/

proc LCA data=mydata.LCAaim2; 
 Title 'LCA with 8 manifest variables n=10,223';
	nclass 1;
	items sexprt2 sexrisk condom2 hltstat2 drink2 drug sti bmi3;
	categories 2 2 2 2 2 2 2 2;
	seed 123456789;
	nstarts 50;
	rho prior= 1;
	maxiter 50000;
	weight WEIGHTVAR;
	cluster panelvar;
run;

proc LCA data=mydata.LCAaim2; 
 Title 'LCA with 8 manifest variables n=10,223';
	nclass 2;
	items sexprt2 sexrisk condom2 hltstat2 drink2 drug sti bmi3;
	categories 2 2 2 2 2 2 2 2;
	seed 123456789;
	ID caseid;
	nstarts 50;
	maxiter 50000;
	rho prior= 1;
	weight weightvar;
	cluster panelvar;
run;

proc LCA data=mydata.LCAaim2 outpost=probs3 outparam=out3 outstderr=std3 outseeds=seed3;
 Title 'LCA with 8 manifest variables n=10,223';
	nclass 3;
	items sexprt2 sexrisk condom2 hltstat2 drink2 drug sti bmi3;
	categories 2 2 2 2 2 2 2 2;
	seed 123456789;
	nstarts 50;
	maxiter 50000;
	rho prior= 1;
	weight weightvar;
	cluster panelvar;
run;

proc LCA data=mydata.LCAaim2 outpost=probs4 outparam=out4 outstderr=std4 outseeds=seed4;
 Title 'LCA with 8 manifest variables n=10,223';
	nclass 4;
	items sexprt2 sexrisk condom2 hltstat2 drink2 drug sti bmi3;
	categories 2 2 2 2 2 2 2 2;
	seed 123456789;
	id caseid;
	nstarts 50;
    MAXITER 50000;
    rho prior= 1;
	weight weightvar;
	cluster panelvar;
run;

proc LCA data=mydata.LCAaim2;
 Title 'LCA with 8 manifest variables n=10,223';
	nclass 5;
	items sexprt2 sexrisk condom2 hltstat2 drink2 drug sti bmi3;
	categories 2 2 2 2 2 2 2 2;
	seed 123456789;
	id caseid;
	nstarts 50;
	MAXITER 50000;
	rho prior= 1;
	weight weightvar;
	cluster panelvar;
run;

proc means data=probs3;
class best; run; 
proc means data=probs4; 
class best; run;

/*************CRAEATING SUM SCORE FOR PRECONCEPTION VARIABLES**********************/

data mydata.LCAaim2;
set mydata.LCAaim2;
 scorevar = sum (sexp, sexr, condm, hlth, alc, drugu, stimen, bmimen);
 if sexprt2=1 then sexp=0; else if sexprt2=2 then sexp=1;
 if sexrisk=1 then sexr=0; else if sexrisk=2 then sexr=1;
 if condom2=1 then condm=0; else if condom=2 then condm=1;
 if hltstat2=1 then hlth=0; else if hlthstat2=2 then hlth=1;
 if drink2=1 then alc=0; else if drink2=2 then alc=1;
 if drug=1 then drugu=0; else if drug=2 then drugu=1;
 if sti=1 then stimen=0; else if sti=2 then stimen=1;
 if bmi3=1 then bmimen=0; else if bmi3=2 then bmimen=1;
 if scorevar =0 then scorevar2=0; else if scorevar=1 then scorevar2=1; else if scorevar=2 then scorevar2=2; 
	else if scorevar=3 then scorevar2=3; 
	else if scorevar in (4:7) then scorevar2=4;
 run;

proc freq data=mydata.LCAaim2; tables sexp sexr condm hlth alc drugu stimen bmimen scorevar scorevar2;run; 

ods rtf file='C:\Users\anakwea\Desktop\Men\RTF_results\2011_2019\descriptives_score_10223';
proc surveyfreq data=mydata.LCAaim2;
tables scorevar2*year/cl nowt row col chisq;
weight WEIGHTVAR;
cluster panelvar;
strata stratvar; 
run; 
ods rtf close;
